import Vue from 'vue';
import Router from 'vue-router';

// 首页
const Index = () => import('@/views/Index');
///登陆
const Login = () => import('@/views/Common/login');
///三查
const Main = () => import('@/views/Common/main');
////用户管理
const UserManger = () => import('@/views/User/usermanger');
/////个人信息管理
// const Bas = ()=>import('@/views/Basinfo/bas')
///角色管理
const Rol = () => import('@/views/Rol/rolmangment');
////日志管理
const Journal = () => import('@/views/Journal/journal');
/////pingfang-unti
const Ping = () => import('@/views/Unit/pingfang');
////系统管理
const System = () => import('@/views/System/administration');
///接口管理
const Joggle = () => import('@/views/Joggle/joggle');
////新增用户
const useradd = () => import('@/views/User/useradd');
////新增页面
const edit = () => import('@/views/Rol/edit');
///////新增页面
const addClient = () => import('@/views/Joggle/addClient');
//404
const cw = () => import('@/views/404');

// 督查四必
const Supervise = () => import('@/views/Supervise');

// 流程管控
const Process = () => import('@/views/Process');

// 通知通报
const Notification = () => import('@/views/Notification');

// 外部联系人
const External = () => import('@/views/External');

Vue.use(Router);

const vueRouter = new Router({
  mode: 'history',
  routes: [
    { path: '/404', name: 'cw', component: cw, hidden: true, sider: false },
    { path: '*', redirect: '/404', hidden: true, sider: false },
    {
      path: '/login',
      name: 'Login',
      component: Login,
      hidden: true,
      sider: false
    },
    { path: '/', name: '首页', component: Index, icon: 'index', id: 0 },
    {
      path: '/main',
      name: '三查工作',
      component: Main,
      iconCls: 'fa fa-home',
      leaf: true,
      icon: 'main',
      id: 4
    },
    {
      path: '/supervise',
      name: '督查四必',
      component: Supervise,
      icon: 'supervise',
      id: 10
    },
    {
      path: '/process',
      name: '流程管控',
      component: Process,
      icon: 'process',
      id: 6
    },
    {
      path: '/notification',
      name: '通知通报',
      component: Notification,
      icon: 'notification',
      id: 8
    },
    {
      path: '/external',
      name: '外部联系人',
      component: External,
      icon: 'external',
      id: 9
    },
    {
      path: '/usermanger',
      name: '用户管理',
      component: UserManger,
      icon: 'user',
      id: 1
    },
    {
      path: '/rolmangment',
      name: '权限管理',
      component: Rol,
      icon: 'role',
      id: 2
    },
    {
      path: '/joggle',
      name: '部门管理',
      component: Joggle,
      icon: 'joggle',
      id: 7
    },
    {
      path: '/journal',
      name: '日志管理',
      component: Journal,
      icon: 'journal',
      id: 3
    },
    {
      path: '/administration',
      name: '系统管理',
      component: System,
      icon: 'system',
      id: 5
    }

    // { path: '/User/useradd', name: 'useradd', component: useradd },
    // { path: '/Rol/edit', name: 'edit', component: edit },
    // { path: '/Joggle/addClient', name: 'addClient', component: addClient },
  ]
});

export const superviseRoutes = [
  {
    path: '/supervise',
    name: '督查四必',
    component: Supervise,
    icon: 'supervise',
    index: 2
  }
];

export const systemRoutes = [
  {
    path: '/notification',
    name: '通知通报',
    component: Notification,
    icon: 'notification'
  },
  {
    path: '/process',
    name: '流程管控',
    component: Process,
    icon: 'process',
    index: 3
  }
];

vueRouter.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token');
  const permissions = JSON.parse(localStorage.getItem('permissions'));
  if (!token && to.name !== 'Login') {
    next({
      name: 'Login'
    });
  } else if (token && to.name == 'Login') {
    localStorage.removeItem('token');
    next({
      name: 'Main'
    });
  } else {
    next();
  }
});

export default vueRouter;
